package com.kfh.ybracelet.chat;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kfh.ybracelet.R;
import com.kfh.ybracelet.base.BaseActivity;
import com.kfh.ybracelet.utils.CommonUtils;
import com.kfh.ybracelet.utils.LogUtil;

import de.greenrobot.event.EventBus;

/**
 * 聊天发送图片的拍照预览页面
 * Created by Aaron on 16/1/15.
 */
public class ShowPhotoActivity extends BaseActivity {

    private ImageView ivphoto;
    private ImageView ivback;
    private TextView tvsend;
    private RelativeLayout rltop;
//    private android.widget.ImageView ivchoose;
//    private android.widget.TextView tvsize;
//    private android.widget.RelativeLayout rlbottom;

    private boolean isHint;
    private String photoUrl;
    private Bitmap bitmapFromPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_show_photo);

        isHint = false;

        initWidget();

        photoUrl = getIntent().getStringExtra("photoUrl");

        LogUtil.e("tag", "图片的路径:" + photoUrl);//13811365683     18500226732   18515576731

        //获取到图片对象
//        CommonUtils.getBitmapFromPath(photoUrl);

        bitmapFromPath = CommonUtils.getBitmapFromPath(photoUrl);
        ivphoto.setImageBitmap(bitmapFromPath);

    }

    private void initWidget() {

//        this.rlbottom = (RelativeLayout) findViewById(R.id.rl_bottom);
//        this.tvsize = (TextView) findViewById(R.id.tv_size);
//        this.ivchoose = (ImageView) findViewById(R.id.iv_choose);
        this.rltop = (RelativeLayout) findViewById(R.id.rl_top);
        this.tvsend = (TextView) findViewById(R.id.tv_send);
        this.ivback = (ImageView) findViewById(R.id.iv_back);
        this.ivphoto = (ImageView) findViewById(R.id.iv_photo);

        ivphoto.setOnClickListener(this);
        ivback.setOnClickListener(this);
        tvsend.setOnClickListener(this);

//        ivchoose.setOnClickListener(this);
    }

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.iv_photo:

                if (isHint) {
//                    rlbottom.setVisibility(View.VISIBLE);
                    rltop.setVisibility(View.VISIBLE);

                } else {
//                    rlbottom.setVisibility(View.GONE);
                    rltop.setVisibility(View.GONE);
                }

                isHint = !isHint;

                break;

            case R.id.iv_back://返回
                finish();
                break;

            case R.id.tv_send://发送

//                EventBus.getDefault().post(ivchoose.isSelected()? Constant.POTO_ORIGINAL:Constant.PHOTO_SMALL);

//                    EventBus.getDefault().post(CommonUtils.getByte(new File(photoUrl)));
                EventBus.getDefault().post(photoUrl);
                if (bitmapFromPath != null) {
                    bitmapFromPath.recycle();
                    bitmapFromPath = null;
                }
                finish();

                break;

//            case R.id.iv_choose:
//
//                ivchoose.setSelected(!ivchoose.isSelected());
//
//                break;

        }

    }
}
